#ifndef PLAYER_CONTROLLER_COMPONENT_H
#define PLAYER_CONTROLLER_COMPONENT_H

#include "..\Components\IComponent.h"
#include "..\EnumDefine.h"
#include "..\Managers\InputManager.h"
#include "..\Generic\GameTime.h"
#include "..\Managers\PhysicsManager.h"
#include "..\Audio\Sound.h"
#include <functional>

class EventManager;
class FlashComponent;
class ProjectileComponent;
class ProjectileFactory;
class VisualComponent;
class PhysicsComponent;
class AnimationComponent;
class Message;
class PlayerControllerComponent : public IComponent
	{
	public:
		virtual const std::string getType() { return "PlayerControllerComponent"; }
		virtual const std::string getFamilyType() { return "PlayerControllerComponent"; }
		
	public:
		PlayerControllerComponent();
		virtual ~PlayerControllerComponent();

		void update(const GameTime& p_gameTime);
		inline void move(b2Vec2& velocity, PhysicsComponent* physicsComponent);
		void init();
		void bulletCallBack(const std::string& p_id, Message* p_message);
		void hit();
		void die();
		
	protected:
		void normal(const GameTime& p_gameTime);
		void dead(const GameTime& p_gameTime);
		void explode();
		void quitGame();
		

		typedef void (PlayerControllerComponent::*FuncPtr)(const GameTime& p_gameTime);
	enum MoveState
	{
		MS_NONE = 0,
		MS_LEFT,
		MS_RIGHT,
		MS_STOP,
		MS_UP,
		MS_DOWN
	};

	enum AnimationState
	{
		ANIM_IDLE,
		ANIM_JUMP,
		ANIM_WALKING,
		ANIM_WIND,
		ANIM_CLIMB,
		ANIM_CLIMB_DONE,
		ANIM_SLIDING,
		ANIM_DAMAGE,
		ANIM_SHOOT_JUMP,
		ANIM_SHOOT_CLIMB,
		ANIM_SHOOT_WALK,
		ANIM_SHOOT_STAND,
	};

	enum CharacterState
	{
		PLAYER_STATE_NORMAL = 0,
		PLAYER_STATE_DEAD,
		PLAYER_STATE_SIZE
	};

		float m_jumpStrength;
		float m_maxSpeed;
		float m_desiredXVel;
		float m_acceleration;
		float m_deacceleration;
		float m_bulletVelocity;
		MoveState m_moveState;
		AnimationState m_animationState;
		float m_timer;
		bool m_isJumping;
		bool m_isClimbing;
		bool m_isSliding;
		bool m_isShooting;
		bool m_canJump;
		int m_maxBullets;
		int m_currentBulletCount;
		int m_jumpTimer;
		int m_elapsedJumpTime;
		int m_playerState;
		ProjectileFactory* m_projectileFactory;
		AnimationComponent* m_animations;
		PhysicsComponent* m_physics;
		VisualComponent* m_visual;
		FlashComponent* m_flash;
		bool m_receivedDamage;
		EventManager* m_eventManager;

		int m_currentState;
		FuncPtr m_funcStatePtr[PLAYER_STATE_SIZE];

		vn::Sound* m_shoot;
		vn::Sound* m_jump;
		vn::Sound* m_damage;
		vn::Sound* m_land;
	};

#endif //PLAYER_CONTROLLER_COMPONENT_H